<template>
  <div class="mt-3">
    <div class="text-right">

      <el-button type="primary" class="!text-4.5" size="large" @click="addCompany(null)">添加新企业</el-button>
    </div>
    <div class="mt-5">
      <div class="p-5 border relative border-#e3e3e3 mb-3 rounded-sm" v-for="(item, i) in enterpriseList" :key="i">
        <div class="text-4.5">
          {{ item.enterpriseName }}

          <el-tag class="ml-8" :type="item.authenticationFlag == 1 ? 'success' : 'danger'">{{ item.authenticationFlag ==
            1 ? '已认证' : '未认证' }}</el-tag>
          <el-tag class="ml-5"
            :type="item.examineResult == 0 ? 'info' : (item.examineResult == 2 ? 'success' : 'danger')">
            {{ transformDict('enterpriseAuditResults', item.examineResult) }}
          </el-tag>
        </div>

        <div class="relative mt-4">
          <p class="col9 text-3.6">
            认证时间：{{ item.createTime }}
          </p>
          <div class="absolute right-5 top-0">
            <el-button v-if="item.examineResult == 1" type="primary" class="w-30 !text-4.5" @click="addCompany(item)"
              size="large">重新认证</el-button>
            <el-button v-if="item.authenticationFlag == '0'" type="primary" class="w-30 !text-4.5"
              @click="addCompany(item)" size="large">立即认证</el-button>
          </div>
        </div>

        <div class="text-4.5 color-#8AA5D2 mt-4">
          <span class=" cursor-pointer" @click="navTo('certiInfoPage', { id: item.id })">
            查看认证信息
          </span>
          <span @click="navTo('contactManagePage', { id: item.id })" class="ml-5 cursor-pointer">
            联系人管理
          </span>
        </div>

      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { useNavTo } from '@/hooks/navTo';
import { getEenterpriceList } from '@/api/enterprise';
import useEnterprise from '@/stores/enterprise';
import { useDict, transformDict } from '@/hooks/dict';

useDict('enterpriseAuditResults')

const { navTo } = useNavTo()
const storeEnter = useEnterprise()
const router = useRouter()
const enterpriseList = ref([])

// 初始化数据
onMounted(() => {
  getEenterpriceList().then(response => {
    console.log('企业列表:', response);
    enterpriseList.value = response.data || []
  }).catch(error => {
    console.error('获取企业列表失败:', error);
  });
})
// function navToCertification() {
//   router.push({
//     path: "certiFormPage"
//   })
// }
function addCompany(obj: object) {
  if (obj) storeEnter.setEnterprise(obj)
  router.push({
    path: "certificationMethods"
  })
}
</script>
